package service.impl;

import java.math.RoundingMode;

import models.OrderDetail;
import prefix.util.OverallUtil;
import processor.OrderDetailProcessor;
import service.OrderDetailService;

public class OrderDetailServiceImpl implements OrderDetailService {

    protected OrderDetail dborderDetail;

    public OrderDetailServiceImpl() {
        this.dborderDetail = new OrderDetail();
    }

    public OrderDetailServiceImpl(OrderDetail orderDetail) {
        this.dborderDetail = orderDetail;
    }

    @Override
    public OrderDetailProcessor getProcessor() {
        // TODO Auto-generated method stub
        return new OrderDetailProcessor(this.dborderDetail);
    }

    public double getLenderPortion(double amountToDispurse, double commitedLoanAmount) {
        double perThisLender;
        perThisLender = (amountToDispurse * this.dborderDetail.getAmount()) / commitedLoanAmount;

        perThisLender = OverallUtil.round2Decimal(perThisLender, RoundingMode.HALF_EVEN).doubleValue();
        return perThisLender;
    }

}
